package com.javacv.plus.extensions.image.steps;

import com.javacv.plus.core.processor.ProcessorContext;
import com.javacv.plus.core.processor.ProcessorStep;
import com.javacv.plus.extensions.image.ImageProcessor;
import com.javacv.plus.extensions.image.ProcessorResult;
import lombok.extern.slf4j.Slf4j;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.global.opencv_core;

/**
 * 亮度调整步骤
 */
@Slf4j
public class BrightnessStep implements ProcessorStep<ImageProcessor, ProcessorResult> {
    private final double factor;

    public BrightnessStep(double factor) {
        this.factor = factor;
    }

    @Override
    public ProcessorResult execute(ImageProcessor processor, ProcessorContext context) throws Exception {
        Mat currentImage = context.getAttribute("currentImage");
        if (currentImage == null) {
            throw new IllegalStateException("当前图像为空");
        }

        log.debug("调整亮度，因子: {}", factor);

        Mat result = new Mat();
        currentImage.convertTo(result, -1, 1.0, factor * 50); // 亮度调整

        context.setAttribute("currentImage", result);
        context.setAttribute("processedImage", result);

        log.debug("亮度调整完成");
        return null;
    }

    @Override
    public String getStepName() {
        return "Brightness";
    }

    @Override
    public int getPriority() {
        return 60;
    }
} 